<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
        .box {
            position: relative;
            width: 200px;
            height: 25px;
            border-bottom: 1px solid red;
        }

        #pwd {
            outline: none;
            border: 0;
        }

        #eye {
            position: absolute;
            right: 10px;
            width: 20px;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <form action="">
        <div class="box">
            <label for="">
                <img src="./imgs/闭眼2.png" alt="" id="eye">
            </label>
            <input type="password" id="pwd">
        </div>
    </form>
    <script>
        let pwd = document.querySelector('#pwd')
        let eye = document.querySelector('#eye')
        flag = 0
        eye.onclick = function () {
            if (flag == 0) {
                pwd.type = 'text'
                eye.src = './imgs/睁眼.png'
                flag = 1
            } else {
                pwd.type = 'password'
                eye.src = './imgs/闭眼2.png'
                flag = 0
            }
            
        }
       
    </script>
</body>

</html>